package cc.ailley.singleton.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 注册登记式单例(线程安全)
 *
 * @author ailley
 */
public class RegisterMap {

    private RegisterMap(){}

    /**
     * 类似于IOC容器
     */
    private static Map<String, Object> container = new ConcurrentHashMap<>();

    public static RegisterMap getInstance(String name){
        if(name == null){
            name = RegisterMap.class.getName();
        }

        if(container.get(name) == null){
            container.put(name, new RegisterMap());
        }

        return (RegisterMap)container.get(name);
    }
}
